<template>
  <div>
    <p class="pinformation" style="margin-top: 7px">搜索条件</p>
    <el-form label-width="100px" :model="queryParams" ref="queryRef">
      <el-row>
        <el-col :span="4">
          <el-form-item label="方案编号：" prop="projectCode">
            <el-input
              v-model="queryParams.projectCode"
              clearable
              maxlength="100"
              @keyup.enter="handleQuery"
              placeholder="请输入方案编号"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="委托单位：" prop="wtCustomName">
            <el-input
              v-model="queryParams.wtCustomName"
              clearable
              maxlength="100"
              @keyup.enter="handleQuery"
              placeholder="请输入委托单位"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="方案名称：" prop="projectName">
            <el-input
              v-model="queryParams.projectName"
              clearable
              maxlength="100"
              @keyup.enter="handleQuery"
              placeholder="请输入方案名称"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="样品编号：" prop="sampleCode">
            <el-input
              v-model="queryParams.sampleCode"
              clearable
              maxlength="100"
              @keyup.enter="handleQuery"
              placeholder="请输入样品编号"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
            <el-form-item label="检测项目：" prop="bucketId" label-width="80">
              <el-input
              v-model="queryParams.jcxmName"
              clearable
              maxlength="100"
              @keyup.enter="handleQuery"
              placeholder="请输入检测项目"
            ></el-input>
            </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="方法编号：" prop="methodCode">
            <el-input
              v-model="queryParams.methodCode"
              clearable
              maxlength="100"
              @keyup.enter="handleQuery"
              placeholder="请输入方法编号"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5">
          <!-- planDate -->
          <el-form-item label="处置时间：">
            <el-date-picker
              v-model="dateRange"
              value-format="YYYY-MM-DD"
              type="daterange"
              :clearable="false"
              :editable="false"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="处置方式：" prop="handleType">
            <el-select
            placeholder="请选择"
            clearable
            v-model="queryParams.handleType"
            filterable
          >
            <el-option
              v-for="dict in proxy.addListNoLimit(sample_handle_type)"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="交接批次：" prop="withNumber">
            <el-input
              v-model="queryParams.withNumber"
              clearable
              maxlength="100"
              @keyup.enter="handleQuery"
              placeholder="请输入交接批次"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="检测类别：" prop="jclbId">
            <el-select
              style="width: 100%"
              clearable
              filterable
              v-model="queryParams.jclbId"
              placeholder="选择检测类别"
            >
              <el-option
                v-for="item in proxy.addListNoLimit(
                  jclbList,
                  'jclbId',
                  'jclbName'
                )"
                :key="item.jclbId"
                :value="item.jclbId"
                :label="item.jclbName"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <!-- ！ -->
        <el-col :span="5">
          <el-button
            type="success"
            style="margin-left: 30px"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button class="business resetBtn" @click="resetQuery"
            >重置</el-button
          >
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <p class="pinformation">样品列表</p>
      <p class="totalStyle">共 {{ total }} 条数据</p>
      <el-row style="padding-bottom: 5px; margin-left: 25px">
        <el-button link type="success">导出处置记录</el-button>
      </el-row>
    </el-row>

    <el-table ref="mainTableRef" :data="sampleList" v-loading="loading">
      <el-table-column
        show-overflow-tooltip
        label="样品编号"
        align="center"
        prop="sampleCode"
        width="160"
      />
      <el-table-column
        show-overflow-tooltip
        label="检测项目"
        align="center"
        prop="jcxmNames"
        width="150"
      >
        <template #default="scope">
          <span v-html="proxy.getSupAndSub(scope.row.jcxmNames)"></span>
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="方案编号"
        align="center"
        prop="projectCode"
        width="100"
      />
      <el-table-column
        show-overflow-tooltip
        label="方案名称"
        align="center"
        prop="projectName"
      />
      <el-table-column
        show-overflow-tooltip
        label="检测点位"
        align="center"
        prop="pointName"
        width="150"
      />
      <el-table-column
        show-overflow-tooltip
        label="采样时间"
        align="center"
        prop="cyDate"
        width="140"
      >
      <template #default="scope"
            >{{ scope.row.cyDate }} {{ scope.row.cyTime }}</template
          >
        </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="保存时长"
        align="center"
        prop="saveTime"
        width="140"
      >
        <template #default="scope"
          >{{ scope.row.saveTime }}{{ scope.row.timeUnitName }}</template
        >
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="交接批次"
        align="center"
        prop="withNumber"
        width="80"
      />
      <el-table-column
        show-overflow-tooltip
        label="检测类别"
        align="center"
        prop="jclbName"
        width="110"
      />
      <el-table-column show-overflow-tooltip label="处置人" align="center" prop="handleUserName" width="90"/>
      <el-table-column show-overflow-tooltip label="处置方式" align="center" prop="handleTypeName" width="90"/>
      <el-table-column show-overflow-tooltip label="处置时间" align="center" prop="handleDate" width="100"/>
      <el-table-column show-overflow-tooltip label="处置原因" align="center" prop="handleReasonName" width="100"/>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup>
import { getDisposedList } from "@/api/sampleManage/retention";
import { allListJclb } from "@/api/store/jclb";
const { proxy } = getCurrentInstance();
const queryParams = ref({pageNum:1,pageSize:10});
const dateRange = ref([]);
const sampleList = ref([])
const total = ref(0)
const loading = ref(false)
const { sample_handle_type, sample_handle_reason, sample_handle_status } = proxy.useDict(
  "sample_handle_type",
  "sample_handle_reason",
  "sample_handle_status"
);

function getList() {
    loading.value = true
    getDisposedList(proxy.addDateRange(queryParams.value, dateRange.value)).then(
    (res) => {
      sampleList.value = res.rows;
      total.value = res.total;
      loading.value = false
    }
  );
}

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  proxy.resetForm("queryRef");
  dateRange.value = [];
  handleQuery();
}

defineExpose({
    getList,
});
const heightParams = ref([{ tableName: "main", bottomHeight: 21 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}

onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});

onUpdated(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "main", bottomHeight: 73 }];
    } else {
      heightParams.value = [{ tableName: "main", bottomHeight: 21 }];
    }
    getTableHeight();
  }
);
const jclbList = ref([]);
allListJclb().then((res) => {
  jclbList.value = res.data;
});
</script>
